<?php

namespace services\models;

use Yii;

/**
 * This is the model class for table "goods_detail".
 *
 * @property string $goods_detail_id
 * @property integer $goods_id
 * @property string $goods_code
 * @property string $goods_name
 * @property integer $goods_type_id
 * @property string $goods_key
 * @property double $cost_price
 * @property double $stock_price
 * @property double $market_price
 * @property double $goods_kg
 * @property integer $goods_supply_id
 * @property integer $register_date
 * @property integer $update_date
 * @property string $produce_date
 * @property integer $period_day
 * @property string $q_index
 * @property integer $buy_number
 * @property integer $limit_start_date
 * @property integer $limit_end_date
 * @property integer $is_gift
 * @property string $storageno
 * @property string $taxrate
 * @property integer $dealkind
 * @property string $deductrate
 * @property string $barcode
 * @property string $stockunit
 * @property string $orderunit
 * @property string $pcsqty
 * @property string $ordqtypit
 * @property string $minstockqty
 * @property string $maxstockqty
 * @property integer $goods_kind
 * @property integer $upv_time
 * @property integer $lock_sales_num
 * @property integer $goods_stock_total
 * @property string $qr_code_pic
 */
class GoodsDetail extends \common\models\GoodsDetail
{
    public static $FREE_POST_YES = 1;
    public static $FREE_POST_NO = 0;

    public static function getDb() {
        return \Yii::$app->db;
    }

    public static function findByGoodsId($goods_id, $fields = '*') {
        $var = self::find()->select($fields)->where('goods_id=:goods_id', [':goods_id' => $goods_id])->one();
        if(!$var) {
            return [];
        }
        
        return \yii\helpers\ArrayHelper::toArray($var);
    }

    /**
     * 通过商品ID，从数据库中获取商品信息。
     * @param int $goods_id 商品ID
     * @return array
     */
    public static function findByGoodsIdFromDb($goods_id) {
        $var = self::find()->where('goods_id=:goods_id', [':goods_id' => $goods_id])->one();
        if(empty($var)) {
            return [];
        }

        return \yii\helpers\ArrayHelper::toArray($var);
    }


    public static function getAllListByGoodsId($goods_id) {
        $vars = self::find()->where('goods_id=:goods_id',['goods_id'=>$goods_id])->one();
        if(!$vars) {
            return [];
        }
        
        return \yii\helpers\ArrayHelper::toArray($vars);
    }
}
